package kaprojecthandler

import (
	"github.com/gin-gonic/gin"
	"yundian/internel/app/dao"
	"yundian/internel/app/helper/request"
	"yundian/internel/pkg/dingo"
	. "yundian/internel/pkg/dingo/result"
)

//  获取项目列表API
func HandleGetKaProjectList(ctx *gin.Context) {
	param := &request.KaProjectListReq{}
	dingo.ErrorIf(ctx.ShouldBindQuery(param)).Unwrap()

	//fmt.Println("hahahah1111: ")

	data := dao.NewKaProjectDao().GetKaProjectList(param)
	// 分页信息
	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  0,
		Data:       data.Unwrap(),
	})(OK)
}

func HandleGetAllProjectList(ctx *gin.Context) {
	data := dao.NewKaProjectDao().GetAllKaProjectList()
	Response(ctx)("", CodeSuccess, data.Unwrap())(OK)
}

//  新增项目信息API
func HandleInsertKaProject(ctx *gin.Context) {
	param := &request.KaProjectInsertReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()

	data := dao.NewKaProjectDao().InsertKaProjectInfo(param)

	Response(ctx)("", CodeInsertSuccess, data)(OK)
}

//  w修改项目信息API
func HandleUpdateKaProject(ctx *gin.Context) {
	param := &request.KaProjectInsertReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()

	data := dao.NewKaProjectDao().UpdateKaProjectInfo(param).Unwrap()

	Response(ctx)("", CodeInsertSuccess, data)(OK)
}

//  删除项目信息API
func HandleDeleteKaProject(ctx *gin.Context) {
	param := &struct {
		Id int `json:"id" binding:"required,gt=0"`
	}{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()

	Response(ctx)("删除成功", CodeDeleteSuccess, dao.NewKaProjectDao().DeleteKaProjectById(param.Id).Unwrap())(OK)
}
